from typing import List
from functools import reduce

class Solution:
    def projectionArea(self, grid: List[List[int]]) -> int:
        z, x = 0, 0
        yCount = []
        for i in range(len(grid)):
            xMax = 0
            for j in range(len(grid[i])):
                if grid[i][j] > 0:
                    z += 1
                xMax = max(xMax, grid[i][j])
                if len(yCount) < j + 1:
                    yCount.append(0)
                yCount[j] = max(yCount[j], grid[i][j])
            x += xMax
        return z + x + reduce(lambda a, b: a + b, yCount)
    
    def projectionArea2(self, grid):
        '''
        一行ok
        '''
        return sum([max(a) for a in zip(*grid)])+sum([max(b) for b in grid])+sum(k>0 for k in sum(grid, []))

